﻿@{
    ViewBag.Title = "商品";
    Layout = "~/Views/Shared/InfoMaste.cshtml";
}

<table id="dg" class="easyui-datagrid" style="width:100%; height: 600px;"
       url="/BasicManage/GetLKGoodsPageList" toolbar="#tb" title="商品" " rownumbers="true" pagination="true"
       pagelist="[15]" fitcolumns="true" singleselect="true">
    <thead>
        <tr>
            <th field="GoodsCode" align="right" width="10%">
                商品代码
            </th>
            <th field="GoodsName" align="right" width="10%">
                商品名称
            </th>
            <th field="TypeName" align="right" width="10%">
                商品类型
            </th>
            @*<th field="GoodsSpecId" align="right" width="10%">
                    商品规格
                </th>
                <th field="Weight" align="right" width="10%">
                    件重
                </th>*@
            <th field="Remark" align="right" width="10%">
                备注
            </th>
            <th field="IsValid" align="right" width="10%" formatter="formatter_IsValid">
                是否有效
            </th>
            <th field="ModifyUser" align="right" width="10%">
                修改人
            </th>
            <th field="ModifyTime" align="right" width="10%">
                修改时间
            </th>
        </tr>
    </thead>
</table>
<div id="tb" style="padding: 3px; height: auto;">
    <span>商品代码</span>
    <input id="GoodsCode" class="easyui-textbox " data-options="validType:'length[1,6]',prompt:'1~6位数字'" style="width: 173px; height: 30px;" />
    <span>商品名称</span>
    <input id="GoodsName" class="easyui-textbox " data-options="validType:'length[1,50]',prompt:'1~50位汉字'" style="width: 173px; height: 30px;" />
    <span>商品类型</span>
    <input name="SelectGoodsTypeId" id="SelectGoodsTypeId" class="easyui-combobox" style="width: 173px; height: 30px; " />
    <div>
        <a href="javascript:" class="easyui-linkbutton" iconcls="icon-add" plain="true" onclick="addLKGoods()">新建</a>
        <a href="javascript:" class="easyui-linkbutton" iconcls="icon-edit" plain="true" onclick="editLKGoods()">编辑</a>
        <a href="javascript:" class="easyui-linkbutton" iconcls="icon-no" plain="true" onclick="delLKGoods()">删除</a>
        <a href="javascript:" class="easyui-linkbutton" plain="true" iconcls="icon-search" onclick="doSearch()">查询</a>
    </div>
</div>
<div id="dlg" class="easyui-dialog" title="新增" data-options="iconCls:'icon-save'"
     closed="true" style="width: 450px; height: 350px; padding: 10px 20px" buttons="#dlg-buttons" modal="true">
    <form id="fm" method="post" novalidate>
        <input type="hidden" name="Id" />
        @*<input type="hidden" id="hidGoodsTypeId" name="GoodsTypeId" />*@
        @*<input type="hidden" id="hidTypeName" name="TypeName" />*@
        <input type="hidden" id="switchbuttonIsValid" name="IsValid" />
        <input type="hidden" id="GoodsCode" name="GoodsCode" />
        <div class="fitem">
            <label>
                商品名称:
            </label>
            <input name="GoodsName" class="easyui-textbox" data-options="required:true,validType:'length[1,50]',prompt:'1~50位汉字或字母'" style="width: 180px; height: 30px;" autocomplete="off" />
        </div>
        <div class="fitem">
            <label>
                商品类别:
            </label>
            <input name="GoodsTypeId" id="GoodsTypeId" class="easyui-combobox" style="width: 180px; height: 30px;" />
        </div>
        <div class="fitem">
            <label>
                是否有效:
            </label>
            <input class="easyui-switchbutton" id="sbIsValid" data-options="onText:'是',offText:'否'">
        </div>
        <div class="fitem">
            <label>
                备注:
            </label>
            <input name="Remark" class="easyui-textbox" data-options="validType:'length[1,100]'" style="width: 250px; height: 30px;" autocomplete="off" />
        </div>
    </form>
</div>
<div id="dlg-buttons">
    <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-ok" onclick="saveLKGoods()">保存</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')">取消</a>
</div>


<script language="javascript" type="text/javascript">
    $(function () {
        InitSelectGoodsTypeId();
    });


    function InitLKGoods() {
        $('#LevelId').combobox({
            url: "/BasicManage/GetLKGoods",
            valueField: 'Id',
            textField: 'LevelName',
            onSelect: function (rec) {
                $("#CustomerLevelId").val(rec.Id);
                $("#CustomerLevelName").val(rec.LevelName);
            }
        });
    }

    function InitSelectGoodsTypeId() {
        //var level_id_sign = 0;//标签
        //$('#SelectLevel').combobox({
        //    url: "/BasicManage/GetLKGoods",
        //    valueField: 'Id',
        //    textField: 'LevelName',
        //    onLoadSuccess: function (data) {
        //        if (level_id_sign == 0) {
        //            data.unshift({
        //                'Id': '',
        //                'LevelName': '全部',
        //                'selected': 'true'
        //            });
        //            level_id_sign++;
        //            $("#SelectLevel").combobox("loadData", data);
        //        }
        //    },
        //    onSelect: function (rec) {
        //        $("#CustomerLevelId").val(rec.Id);
        //        $("#CustomerLevelName").val(rec.LevelName);
        //    }
        //});
        $('#SelectGoodsTypeId').combotree({
            url: "/BasicManage/GetTypeComboxTree",
            editable: false,
            valueField: 'Id',
            textField: 'TypeName'
        });
    }

    function InitGoodsType() {
        $('#GoodsTypeId').combotree({
            url: "/BasicManage/GetTypeComboxTree",
            editable: false,
            valueField: 'Id',
            textField: 'TypeName',
            onSelect: function (rec) {
                //$("#hidGoodsTypeId").val(rec.id);
                //$("#hidTypeName").val(rec.text);
            }
        });
    }

    function doSearch() {
        $('#dg').datagrid('load', {
            GoodsCode: $('#GoodsCode').val(),
            GoodsType: $('#SelectGoodsTypeId').combobox('getValue'),
            GoodsName: $('#GoodsName').val(),
            //IsValid: $('#IsValid').combobox('getValue'),
        });
    }

    function addLKGoods() {
        InitGoodsType();
        $('#fm').form('clear');
        $('#dlg').dialog('open');
        $('#sbIsValid').switchbutton({ checked: 'true' });
        url = '/BasicManage/AddLKGoods';
    }

    function editLKGoods() {
        var row = $('#dg').datagrid('getSelected');
        if (!row) {
            Helper.Show('请选择需要编辑的信息?');
            return;
        }
        $('#dlg').dialog('open').dialog('setTitle', '编辑');
        InitGoodsType();
        $.messager.progress({
            title: '请稍后',
            msg: '数据加载中...',
        });
        window.setTimeout(function () {
            $('#fm').form('load', row);
            $('#GoodsTypeId').combobox('setValue', row.GoodsTypeId);
            $('#GoodsTypeId').combobox('setText', row.TypeName);
            $('#sbIsValid').switchbutton({ checked: row.IsValid });
            $.messager.progress('close');
        }, 1000);

        url = "/BasicManage/EditLKGoods";
    }

    function delLKGoods() {
        var row = $('#dg').datagrid('getSelected');
        if (!row) {
            Helper.Show('请选择需要删除的信息?');
            return false;
        }
        $.messager.confirm('提示信息', '您确认要删除吗?', function (r) {
            if (!r) { return false; }
            $.post("/BasicManage/DeleteLKGoods", { id: row.Id }, function (json) {
                Helper.Show(json.Msg);
                if (json.Success) {
                    doSearch();
                }
            });
        });
    }

    function saveLKGoods() {
        $("#switchbuttonIsValid").val($('#sbIsValid').switchbutton('options').checked);
        $('#fm').form('submit', {
            url: url,
            onSubmit: function () {
                return $(this).form('validate');
            },
            success: function (json) {
                var json = eval('(' + json + ')');
                Helper.Show(json.Msg);
                if (json.Success) {
                    $('#fm').form('clear');
                    $('#dlg').dialog('close');
                    $('#dg').datagrid('reload');
                }
            }
        });
    }

    function formatter_IsValid(value, rowData, rowIndex) {
        //return rowData.IsValid ? '<a href="javascript:" onclick="editBusinessCompanyInfoIsStop(' + rowData.Id + ',true)" style="color:black;">启用</a>' : '<a href="javascript:" onclick="editBusinessCompanyInfoIsStop(' + rowData.Id + ',true)" style="color:black;">停用</a>';
        return rowData.IsValid ? '启用' : '停用';
    }
</script>



